#ifndef DEF_SFML_MAP_H
#define DEF_SFML_MAP_H

#include <SFML/Graphics.hpp>
#include "../Map.h"

using namespace sf;

class SFMLMap
{
   public:
   
      SFMLMap();
      SFMLMap(RenderWindow* p_App, Map* p_parent);
      
      IntRect indice_to_rect(int i);
      void cutTileset();
      void draw();
      
      Sprite sprite_on_layer[N_LAYER][MAP_DIM_MAX][MAP_DIM_MAX];
      
      
      inline pix_coord convert(map_coord c) { return pix_coord(c.iCol*TILE_DIM+parent->start.x,c.iLig*TILE_DIM+parent->start.y); }
      
      inline void setSprite(int L, map_coord to_convert, Sprite spr) { spr.SetPosition(convert(to_convert).x,convert(to_convert).y); sprite_on_layer[L][to_convert.iLig][to_convert.iCol] = spr; }
      inline Sprite getSprite(int L, map_coord c) { return sprite_on_layer[L][c.iLig][c.iCol]; }
      
      static void loadTilesetImage()
      {
         tilesetImage.LoadFromFile(tileset_def_path+"test.png");
         tilesetImage.CreateMaskFromColor(tilesetImage.GetPixel(0,0),0);
      }
      
      bool valide(map_coord c);
      
      void initSelector(sf::Color c);
      void showSelector();
      void unshowSelector();
      void activeSelector();
      void unactiveSelector();
      void moveSelector(const int iDir);
      void setSpriteOnSelector(Sprite spr);
      
      inline bool isActive() { return active_selector; }
      
      map_coord posSelector;
      
   private:
      Shape Selector;
      Sprite spriteSelector;
      static Image tilesetImage;
      Map* parent;
      RenderWindow* App;
      bool show_selector;
      bool active_selector;
      
};

#endif
